package com.lagou.edu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 13771
 * @date 2020/8/9 22:40
 * @description
 */
@Controller
@RequestMapping("/user")
public class LoginController {

    @RequestMapping("/login")
    @ResponseBody
    public String login(@RequestParam("username") String username,@RequestParam("password") String password,
                          HttpServletRequest request){

        if("admin".equals(username) && "admin".equals(password)){
            request.getSession().setAttribute("username",username);
            return  "{\"code\":200,\"message\":\"sucess\"}";
        }else {
            request.getSession().removeAttribute("username");
            return "{\"code\":500,\"message\":\"error\"}";
        }

    }
}
